  function initAjax() {
     try { return new ActiveXObject("Msxml2.XMLHTTP");  } catch(e) {} //IE
     try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
     try { return new XMLHttpRequest();          } catch(e) {} //Native Javascript
     alert("XMLHttpRequest not supported");
     return null;
  };

  function getSubCetegory(){

    var cat_id = document.getElementById("form_category_id_").value;

    if(trimString(cat_id)==""){
      alert("กรุณาเลือกหมวดหมู่หลักให้ถูกต้อง");
    }else{
      //Clean brand
      document.getElementById("subcat").innerHTML = '<select id="form_brand_id_" style="width: 120px; height: 150px; background-image : url(modules/InnoForum/pnimages/ajax-loader-2.gif) ; background-repeat: no-repeat; background-position: 50% 50% ;none repeat scroll 0% 0% rgb(255, 255, 255);" size="8"></select>';
      document.getElementById("brand").innerHTML = '<select id="form_brand_id_" style="width: 120px; height: 150px; background: none repeat scroll 0% 0% rgb(255, 255, 255);" size="8"></select>';
      document.getElementById("model").innerHTML = '<select id="form_model_id_" style="width: 120px; height: 150px; background: none repeat scroll 0% 0% rgb(255, 255, 255);" size="8"></select>';
      document.getElementById("carproperty").innerHTML = '';

       var req = initAjax();
       req.onreadystatechange = function () { 
            if (req.readyState==4) {
                 if (req.status==200) {
                      document.getElementById("subcat").innerHTML=req.responseText; //รับค่ากลับมา
                 } 
            }
       };
       //req.open("GET", "locale.php?data="+src+"&val="+val); //create connection

      req.open("POST", "index.php?module=InnoForum&type=ajax&func=list&ctrl=Sub_Category&category_id="+cat_id+"&enable=1"); //create connection
      req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); // set Header
      req.send(null); //ส่งค่า
    }
    
  }

  function getSubcategoryBrand(){

    var cat_id = document.getElementById("form_category_id_").value;
    var subcat_id = document.getElementById("form_subcategory_id_").value;
    if(trimString(cat_id)=="" || trimString(subcat_id)==""){
      alert("กรุณาเลือกหมวดหมู่ย่อยให้ถูกต้อง");
    }else{

      //Clean model
      document.getElementById("brand").innerHTML = '<select id="form_brand_id_" style="width: 120px; height: 150px; background-image : url(modules/InnoForum/pnimages/ajax-loader-2.gif) ; background-repeat: no-repeat; background-position: 50% 50% ;none repeat scroll 0% 0% rgb(255, 255, 255);" size="8"></select>';
      document.getElementById("model").innerHTML = '<select id="form_model_id_" style="width: 120px; height: 150px; background: none repeat scroll 0% 0% rgb(255, 255, 255);" size="8"></select>';
      document.getElementById("carproperty").innerHTML = '';

       var req = initAjax();
       req.onreadystatechange = function () { 
            if (req.readyState==4) {
                 if (req.status==200) {

                    var result = req.responseText;
                    //alert(result);
                    if(result == 400){
                      document.getElementById("brand").innerHTML=  "<select name=form[brand_id]"+
                                                                              " id='form_brand_id_'"+
                                                                              " style='width: 120px; height: 150px; background: none repeat scroll 0% 0% rgb(220, 220, 220);'"+
                                                                              " size='8'"+
                                                                      ">"+
                                                                        "<option value='99999' selected></option>"+
                                                                        "<option value='99999'></option>"+
                                                                        "<option value='99999'></option>"+
                                                                        "<option value='99999'>สิ้นสุดการเลือกแล้ว</option>"+
                                                                        "<option value='99999'></option>"+
                                                                      "</select>";
                      document.getElementById("model").innerHTML=  "<select name=form[model_id]"+
                                                                              " id='form_model_id_'"+
                                                                              " style='width: 120px; height: 150px; background: none repeat scroll 0% 0% rgb(220, 220, 220);'"+
                                                                              " size='8'"+
                                                                      ">"+
                                                                        "<option value='99999' selected></option>"+
                                                                        "<option value='99999'></option>"+
                                                                        "<option value='99999'></option>"+
                                                                        "<option value='99999'>สิ้นสุดการเลือกแล้ว</option>"+
                                                                        "<option value='99999'></option>"+
                                                                      "</select>";
                      getSubcategoryCarProperty();
                    }else{
                      document.getElementById("brand").innerHTML= req.responseText;
                    }
                 } 
            }
       };
       //req.open("GET", "locale.php?data="+src+"&val="+val); //create connection
      //var subcat_id = document.getElementById("form_subcategory_id_").value;

      req.open("POST", "index.php?module=InnoForum&type=ajax&func=list&ctrl=SubcategoryBrand&subcategory_id="+subcat_id+"&enable=1"); //create connection
      req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); // set Header
      req.send(null); //ส่งค่า
    }
  }
  function getSubcategoryModel(){

    var cat_id = document.getElementById("form_category_id_").value;
    var subcat_id = document.getElementById("form_subcategory_id_").value;
    var brand_id = document.getElementById("form_brand_id_").value;

    if(trimString(cat_id)=="" || trimString(subcat_id)=="" || trimString(brand_id)==""){
      alert("กรุณาเลือกยี่ห้อให้ถูกต้อง");
    }else{

      document.getElementById("model").innerHTML = '<select id="form_model_id_" style="width: 120px; height: 150px; background-image : url(modules/InnoForum/pnimages/ajax-loader-2.gif) ; background-repeat: no-repeat; background-position: 50% 50% ;none repeat scroll 0% 0% rgb(255, 255, 255);" size="8"></select>';
      document.getElementById("carproperty").innerHTML = '';

      var req = initAjax();
      req.onreadystatechange = function () { 
          if (req.readyState==4) {
               if (req.status==200) {

                  var result = req.responseText;
                  if(result == 400){
                    document.getElementById("model").innerHTML=  "<select name=form[model_id]"+
                                                                            " id='form_model_id_'"+
                                                                            " style='width: 120px; height: 150px; background: none repeat scroll 0% 0% rgb(220, 220, 220);'"+
                                                                            " size='8'"+
                                                                    ">"+
                                                                      "<option value='99999' selected></option>"+
                                                                      "<option value='99999'></option>"+
                                                                      "<option value='99999'></option>"+
                                                                      "<option value='99999'>สิ้นสุดการเลือกแล้ว</option>"+
                                                                      "<option value='99999'></option>"+
                                                                    "</select>";
                    getSubcategoryCarProperty();
                  }else{
                    document.getElementById("model").innerHTML= req.responseText;
                  }
               } 
          }
      };
      //req.open("GET", "locale.php?data="+src+"&val="+val); //create connection

      req.open("POST", "index.php?module=InnoForum&type=ajax&func=list&ctrl=SubcategoryModel&subcategory_id="+subcat_id+"&brand_id="+brand_id+"&enable=1"); //create connection
      req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); // set Header
      req.send(null); //ส่งค่า
    }
  }
/*
  function getBrand(){
    //Clean brand
    document.getElementById("brand").innerHTML = '<select id="form_brand_id_" style="width: 120px; height: 150px; background-image : url(modules/InnoForum/pnimages/ajax-loader-2.gif) ; background-repeat: no-repeat; background-position: 50% 50% ;none repeat scroll 0% 0% rgb(255, 255, 255);" size="8"></select>';
    document.getElementById("model").innerHTML = '<select id="form_model_id_" style="width: 120px; height: 150px; background: none repeat scroll 0% 0% rgb(255, 255, 255);" size="8"></select>';
    document.getElementById("carproperty").innerHTML = '';

     var req = initAjax();
     req.onreadystatechange = function () { 
          if (req.readyState==4) {
               if (req.status==200) {

                  var result = req.responseText;
                  //alert(result);
                  if(result == 400){
                    document.getElementById("brand").innerHTML=  "<select name=form[brand_id]"+
                                                                            " id='form_brand_id_'"+
                                                                            " style='width: 120px; height: 150px; background: none repeat scroll 0% 0% rgb(220, 220, 220);'"+
                                                                            " size='8'"+
                                                                    ">"+
                                                                      "<option value='99999' selected></option>"+
                                                                      "<option value='99999'></option>"+
                                                                      "<option value='99999'></option>"+
                                                                      "<option value='99999'>สิ้นสุดการเลือกแล้ว</option>"+
                                                                      "<option value='99999'></option>"+
                                                                    "</select>";
                    document.getElementById("model").innerHTML=  "<select name=form[model_id]"+
                                                                            " id='form_model_id_'"+
                                                                            " style='width: 120px; height: 150px; background: none repeat scroll 0% 0% rgb(220, 220, 220);'"+
                                                                            " size='8'"+
                                                                    ">"+
                                                                      "<option value='99999' selected></option>"+
                                                                      "<option value='99999'></option>"+
                                                                      "<option value='99999'></option>"+
                                                                      "<option value='99999'>สิ้นสุดการเลือกแล้ว</option>"+
                                                                      "<option value='99999'></option>"+
                                                                    "</select>";
                    getCarProperty();
                  }else{
                    document.getElementById("brand").innerHTML= req.responseText;
                  }
               } 
          }
     };
     //req.open("GET", "locale.php?data="+src+"&val="+val); //create connection
    //var subcat_id = document.getElementById("form_subcategory_id_").value;

    var subcat_id = document.getElementById("form_subcategory_id_").value;

    req.open("POST", "index.php?module=InnoForum&type=ajax&func=list&ctrl=Brand&subcategory_id="+subcat_id+"&enable=1"); //create connection
    req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); // set Header
    req.send(null); //ส่งค่า
    
  }

  function getModel(){

    var cat_id = document.getElementById("form_category_id_").value;
    var subcat_id = document.getElementById("form_subcategory_id_").value;
    var brand_id = document.getElementById("form_brand_id_").value;

    if(trimString(cat_id)=="" || trimString(subcat_id)=="" || trimString(brand_id)==""){
      alert("กรุณาเลือกยี่ห้อให้ถูกต้อง");
    }else{

      document.getElementById("model").innerHTML = '<select id="form_model_id_" style="width: 120px; height: 150px; background-image : url(modules/InnoForum/pnimages/ajax-loader-2.gif) ; background-repeat: no-repeat; background-position: 50% 50% ;none repeat scroll 0% 0% rgb(255, 255, 255);" size="8"></select>';
      document.getElementById("carproperty").innerHTML = '';

      var req = initAjax();
      req.onreadystatechange = function () { 
          if (req.readyState==4) {
               if (req.status==200) {

                  var result = req.responseText;
                  if(result == 400){
                    document.getElementById("model").innerHTML=  "<select name=form[model_id]"+
                                                                            " id='form_model_id_'"+
                                                                            " style='width: 120px; height: 150px; background: none repeat scroll 0% 0% rgb(220, 220, 220);'"+
                                                                            " size='8'"+
                                                                    ">"+
                                                                      "<option value='99999' selected></option>"+
                                                                      "<option value='99999'></option>"+
                                                                      "<option value='99999'></option>"+
                                                                      "<option value='99999'>สิ้นสุดการเลือกแล้ว</option>"+
                                                                      "<option value='99999'></option>"+
                                                                    "</select>";
                    getSubcategoryCarProperty();
                  }else{
                    document.getElementById("model").innerHTML= req.responseText;
                  }
               } 
          }
      };
      //req.open("GET", "locale.php?data="+src+"&val="+val); //create connection

      req.open("POST", "index.php?module=InnoForum&type=ajax&func=list&ctrl=Model&brand_id="+brand_id+"&enable=1"); //create connection
      req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); // set Header
      req.send(null); //ส่งค่า
    }
  }
  */
/*
  function getCarProperty(){
    document.getElementById("carproperty").innerHTML = '<select id="form_carproperty_id_" style="width: 120px; height: 150px; background-image : url(modules/InnoForum/pnimages/ajax-loader-2.gif) ; background-repeat: no-repeat; background-position: 50% 50% ;none repeat scroll 0% 0% rgb(255, 255, 255);" size="8"></select>';
    document.getElementById("carproperty").innerHTML = '';
    var req = initAjax();
    req.onreadystatechange = function () { 
        if (req.readyState==4) {
             if (req.status==200) {

                var result = req.responseText;
                if(result == 400){
                  document.getElementById("carproperty").innerHTML=  "<span name='form[carproperty_id]' value='99999'>ไม่มีหมวดหมู่</span>";
                }else{
                  document.getElementById("carproperty").innerHTML= req.responseText;
                }
             } 
        }
    };
     //req.open("GET", "locale.php?data="+src+"&val="+val); //create connection
    var category_id    = document.getElementById("form_category_id_").value;
    //var subcategory_id = document.getElementById("form_subcategory_id_").value;
    var subcat_id = document.getElementById("form_subcategory_id_").value;
    var brand_id       = document.getElementById("form_brand_id_").value;
    var model_id       = document.getElementById("form_model_id_").value;
    var url = "index.php?module=InnoForum&type=ajax&func=list&ctrl=CarProperty&category_id="+category_id+"&subcategory_id="+subcat_id+"&brand_id="+brand_id+"&model_id="+model_id;
    req.open("POST", url); //create connection
    req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); // set Header
    req.send(null); //ส่งค่า
    
  }
*/
  function getSubcategoryCarProperty(){


    var cat_id = document.getElementById("form_category_id_").value;
    var subcat_id = document.getElementById("form_subcategory_id_").value;
    var brand_id = document.getElementById("form_brand_id_").value;
    var model_id = document.getElementById("form_model_id_").value;



    if(trimString(cat_id)=="" || trimString(subcat_id)=="" || trimString(brand_id)=="" || trimString(model_id)==""){
      alert("กรุณาเลือกรุ่นรถให้ถูกต้อง");
    }else{

      document.getElementById("carproperty").innerHTML = '<select id="form_carproperty_id_" style="width: 120px; height: 150px; background-image : url(modules/InnoForum/pnimages/ajax-loader-2.gif) ; background-repeat: no-repeat; background-position: 50% 50% ;none repeat scroll 0% 0% rgb(255, 255, 255);" size="8"></select>';
      document.getElementById("carproperty").innerHTML = '';
      var req = initAjax();
      req.onreadystatechange = function () { 
          if (req.readyState==4) {
               if (req.status==200) {

                  var result = req.responseText;
                  if(result == 400){
                    document.getElementById("carproperty").innerHTML=  "<span name='form[carproperty_id]' value='99999'>ไม่มี</span>";
                  }else{
                    document.getElementById("carproperty").innerHTML= req.responseText;
                  }
               } 
          }
      };



      var url = "index.php?module=InnoForum&type=ajax&func=list&ctrl=SubcategoryCarProperty&subcategory_id="+subcat_id;
      req.open("POST", url); //create connection
      req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); // set Header
      req.send(null); //ส่งค่า
    }
  }